package com.hp.attendance.dao;

import com.hp.attendance.entity.Attendance;
import com.hp.attendance.entity.Employee;
import com.hp.attendance.entity.dto.LateDTO;
import com.hp.attendance.util.BaseDAO;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class AttendanceDao extends BaseDAO {
    //查询考勤记录
    public List<Attendance> listAttendance() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String sql="select * from attendance order by id desc";
        return queryList(sql,new Object[0],new Attendance());
    }
    //查询员工名字
    public Employee employeeName(Integer employee_number) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String sql="select * from employee where employee_number=?";
        Object[] obj={employee_number};
        return queryOne(sql,obj,new Employee());
    }

    //查询员工迟到次数
    public List<LateDTO> getLate() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String sql ="select a.employee_number eNumber,e.name eName,count(a.start_type) number from attendance a,employee e " +
                " where a.employee_number=e.employee_number and a.start_type='迟到' group by a.employee_number ";
        List<LateDTO> lateDTOS = queryList(sql, new Object[0], new LateDTO());
        return lateDTOS;
    }
}
